﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;

/// <summary>
/// Summary description for PL
/// </summary>
public class PL
{
	private const string STORED_PROCEDURE = "PL_Get";
	DatabaseManager db;
	MySqlDataReader reader;

	public string Id { get; set; }
  public int Year { get; set; }
	public int DirectCost { get; set; }
	public int GrossMargin { get; set; }
	public int Result { get; set; }
	public int Revenue { get; set; }

	public PL()
	{
    db = new DatabaseManager();
	}

  public void Load(string id, int year)
  {
    db.AddParameter("@id", id);
    db.AddParameter("@year", year);
    using (reader = db.ExecuteStoredProcedure(STORED_PROCEDURE))
    {
      while (reader.Read())
      {
        Id = reader.GetString("id");
        Year = Convert.ToInt32(reader.GetString("year"));
        DirectCost = Convert.ToInt32(reader.GetString("direct_cost"));
        GrossMargin = Convert.ToInt32(reader.GetString("gross_margin"));
        Result = Convert.ToInt32(reader.GetString("result"));
        Revenue = Convert.ToInt32(reader.GetString("revenue"));
      }
    }
  }
}